package com.jmail.sample;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.jmail.model.entity.User;
import org.eclipse.nebula.widgets.collapsiblebuttons.CollapsibleButtons;
import org.eclipse.nebula.widgets.collapsiblebuttons.IColorManager;
import org.eclipse.nebula.widgets.collapsiblebuttons.CustomButton;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;

public class MailViewer extends Shell {

	private User loginedUser = null;
	
	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			MailViewer shell = new MailViewer(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * @param display
	 */
	public MailViewer(Display display) {
		super(display, SWT.SHELL_TRIM);
		
		createContents();
	}

	public User getLoginedUser() {
		return loginedUser;
	}

	public void setLoginedUser(User loginedUser) {
		this.loginedUser = loginedUser;
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("View");
		setSize(800, 600);

		CollapsibleButtons collapsibleButtons = new CollapsibleButtons(this, SWT.NONE, IColorManager.SKIN_AUTO_DETECT);
		collapsibleButtons.setBounds(10, 63, 129, 203);
		collapsibleButtons.setLayoutData(new GridData(GridData.GRAB_VERTICAL | GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END));
		
		CustomButton customButton = collapsibleButtons.addButton("Inbox", "Inbox", null, null);
		customButton.setToolTipText("Inbox");
		customButton.setToolTip("Inbox");
		customButton.setText("Inbox");
		//customButton.setBounds(5, 10, 100, 20);
		
		Button btnComposeMail = new Button(this, SWT.NONE);
		btnComposeMail.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				MailComposer mailComposer = new MailComposer(getDisplay());
				mailComposer.setLoginedUser(loginedUser);
				mailComposer.open();
				mailComposer.layout();
			}
		});
		btnComposeMail.setBounds(10, 10, 110, 23);
		btnComposeMail.setText("Compose mail");
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
